from PyPhysLeo.dynamics import PdmCudaF,SymplecticEulerCudaF,FixedFreedomCudaF,GravityCudaF,VelocityDampingCudaF
from PyPhysLeo.display import PointRenderCudaF
from PyPhysLeo.geometry import Smesh
from PyPhysLeo.scene_graph import Node,DynamicBodyF,SceneGraph
from PyQt5.QtCore import QObject

def stvkBunny(control):
    dt = 0.001
    print('Stvk Bunny Demo')
    
    pdm = SymplecticEulerCudaF()
    pdm.fixed_freedom_ = FixedFreedomCudaF()
    pdm.gravity_ = GravityCudaF()

    pdm.internal_force_ = PdmCudaF()
    pdm.velocity_damping_ = VelocityDampingCudaF()
    
    bunny = Smesh()
    bunny.loadFromFile('../Model/Bunny/bunny.smesh')
    
    root = Node()
    pdm_body = DynamicBodyF(pdm, "pdm bunny")
    root.addChild(pdm_body)
    pdm_data = pdm_body.getSimData()
    pdm_data.readGeometry(bunny)
    pdm_data.readSimulationConfig('../Model/Bunny/bunny.ini')

    pdm_body.addRender(PointRenderCudaF())
    pdm_body.setMaxDt(dt)

    control.gravities_ = [pdm.gravity_]
    control.dampings_ = [pdm.velocity_damping_]
    g = pdm_data.gravity_acceleration_
    g
    control.ui.gravity_x.setValue(g[0])
    control.ui.gravity_y.setValue(g[1])
    control.ui.gravity_z.setValue(g[2])
    control.ui.velocity_damping.setValue(pdm_data.velocity_damping_param_)

    return SceneGraph(root)